package com.example.fp.zlz.service;

import com.example.fp.zlz.entity.Userinfo;
import com.example.fp.zlz.mapper.AdminMapper;
import com.example.fp.zlz.util.MyuserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

@Component
public class MyUserDetailsService implements UserDetailsService {
	@Autowired
	AdminMapper adminMapper;

	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException{
		// TODO Auto-generated method stub
		//这里可以通过数据库来查找到实际的用户信息，这里我们先模拟下,后续我们用数据库来实现
		Userinfo userinfo=adminMapper.selectbyusername(username);
		if(userinfo.getPassword()!=null) {
			//假设返回的用户信息如下;
			return new MyuserService(userinfo.getUsername(), userinfo.getPassword(), "ROLE_ADMIN", true,true,true, true);
		}
		return null;
	}

}
